package com.stylefeng.guns.modular.fileManage.service.impl;

import com.stylefeng.guns.common.persistence.model.ZyTea;
import com.stylefeng.guns.common.persistence.dao.ZyTeaMapper;
import com.stylefeng.guns.common.persistence.model.ZyTeaPicture;
import com.stylefeng.guns.modular.fileManage.dao.ZyTeaPictureDao;
import com.stylefeng.guns.modular.fileManage.service.IZyTeaService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lsy
 * @since 2017-12-21
 */
@Service
public class ZyTeaServiceImpl extends ServiceImpl<ZyTeaMapper, ZyTea> implements IZyTeaService {

    @Autowired
    private ZyTeaPictureDao zyTeaPictureDao;

    /**
     * 关联图片
     *
     * @param teaId
     * @param pictureId
     * @param label
     * @param sequence
     */
    public void selectorPictureByTea(Integer teaId, Integer pictureId, String label, Integer sequence) {
        if (teaId != null && pictureId != null) {
            ZyTeaPicture zyTeaPicture = new ZyTeaPicture();
            zyTeaPicture.setTeaId(teaId);
            zyTeaPicture.setPictureId(pictureId);
            if(label!=null){
                zyTeaPicture.setLabel(label);
            }
            if(sequence!=null){
                zyTeaPicture.setSequence(sequence);
            }
            zyTeaPictureDao.insert(zyTeaPicture);
        }
    }


    /**
     * 取消关联指定id集合的图片
     *
     * @param teaId
     * @param ids
     */
    public void cancelSelectorByTeaId(Integer teaId, Integer[] ids) {
        if(ids.length>0 && teaId!=null){
            zyTeaPictureDao.deleteIdsByteaId(teaId,ids);
        }
    }
}
